package com.cykj.service.serviceImpl;

import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailException;
import cn.hutool.extra.mail.MailUtil;
import com.cykj.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EmailServicelmpl implements EmailService {
    @Autowired
    private MailAccount mailAccount;
    @Override
    public void sendMail(String toEmail, String code) {
        String subject = "邮箱验证码";
        String content = "您的验证码是：" + code + "，有效期为 5 分钟。";
        System.out.println(content);
        System.out.println(mailAccount);
        System.out.println(code);

        try {
            MailUtil.send(mailAccount,toEmail, subject, content, false);
            System.out.println(mailAccount);
        } catch (MailException e) {
            e.printStackTrace();

        }
    }
}
